using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.PlayerLoop;


public class DamageBar : MonoBehaviour
{
    Transform cam;

    public int damage;

    private float timer = 0f;

    private float time = 0.8f;
    


    public Transform startPoint;

    // Start is called before the first frame update
    void OnEnable()
    {
        GetComponent<TextMesh>().text = "-" + damage.ToString();
        cam = Camera.main.transform;
        gameObject.transform.position = startPoint.position;
        transform.DOMove(transform.position + Vector3.up,time);
        DOTween.To(() => gameObject.GetComponent<TextMesh>().fontSize,
            x => gameObject.GetComponent<TextMesh>().fontSize = x, 10, time);

    }

    private void Update()
    {
        timer += Time.deltaTime;
        gameObject.transform.forward = cam.forward;
        if (timer >= time)
            gameObject.SetActive(false);
    }
}
